package cn.login;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;



	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//admin 12345
		//设置响应内容
		response.setContentType("text/html;charset=gbk");
		//创建输入对象
		PrintWriter out=response.getWriter();
		try{
		//您可以调用 request.getParameter()方法来获取表单参数的值。
		//获取表单提交的参数，即表单中username的参数，和password的参数	
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		//创建session会话对象
		HttpSession session=request.getSession();
	    if(username.trim().equals("youyou")&&password.equals("123456")){
			request.getSession().setAttribute("loginstatus", "loginSuccess");
			response.sendRedirect("/Servletaaaa/admin/main.jsp");
		}else{
		
			request.getRequestDispatcher("login.jsp").forward(request, response);
		}}
		finally{
				out.close();}
	}

}
